//
//  LLTabBarController.m
//  lrlzapp
//
//  Created by dl on 16/2/22.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLTabBarController.h"
#import "LLGuidanceViewController.h"

@interface LLTabBarController ()

@end

@implementation LLTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.tintColor = UI_COLOR_RED;
    self.delegate = self;
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *_Nonnull item, NSUInteger idx, BOOL *_Nonnull stop) {
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UI_COLOR_RED, NSForegroundColorAttributeName, nil]
                            forState:UIControlStateSelected];

        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIColorFromRGB(0x787878), NSForegroundColorAttributeName, nil]
                            forState:UIControlStateNormal];
    }];

    [[LLNavigationControllerStack sharedInstance] pushNavigationController:self.viewControllers[0]];
    [[self
            rac_signalForSelector:@selector(tabBarController:didSelectViewController:)
                     fromProtocol:@protocol(UITabBarControllerDelegate)]
            subscribeNext:^(RACTuple *tuple) {
                [[LLNavigationControllerStack sharedInstance] popNavigationController];
                [[LLNavigationControllerStack sharedInstance] pushNavigationController:tuple.second];

                CATransition *transition = [CATransition animation];
                transition.type = kCATransitionFade;
                transition.removedOnCompletion = YES;
                [self.view.layer addAnimation:transition forKey:nil];
            }];

    if (![SSKeychain getLastStateAndLaunch]) {
        LLGuidanceViewController *guidanceVC = [[LLGuidanceViewController alloc] init];
        [self addChildViewController:guidanceVC];
        [self.view addSubview:guidanceVC.view];
    }

}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    return YES;
}

@end